package com.lagou.edu.service.impl;

import com.lagou.edu.service.IEmailService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.MailException;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;

import javax.annotation.Resource;

/**
 * @Description TODO
 * @Classname IEmailServerImpl
 * @Date 2021/5/30 17:50
 * @Author ch'ien
 */

@Service
public class IEmailServerImpl implements IEmailService {

    @Resource
    private JavaMailSender javaMailSender;

    @Value("${spring.mail.username}")
    private String from;

    @Override
    public Boolean send(String to, String msg) {
        SimpleMailMessage msgTo = new SimpleMailMessage();
        msgTo.setFrom(from);
        msgTo.setTo(to);
        msgTo.setSubject("验证码");
        msgTo.setText(msg);
        try {
            javaMailSender.send(msgTo);
        } catch (MailException e) {
            e.printStackTrace();
        }
        return true;
    }


}
